package lk.service;

import lk.exception.RestfulRecord;
import org.springframework.web.multipart.MultipartFile;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import javax.servlet.http.HttpServletResponse;

/**
 * 文件操作业务层接口
 *
 */
public interface FileService {

    /**
     *  参数名称定义
     */
    String FILE_UPLOAD_TYPE_NAME = "upload.type";
    String FILE_SERVICE_PATH_NAME = "service.path";
    String FILE_ADDRESS_NAME = "ftp.address";
    String FILE_PORT_NAME = "ftp.port";
    String FILE_USERNAME_NAME = "ftp.userName";
    String FILE_PASSWORD_NAME = "ftp.password";
    String FTP_BASE_PATH_NAME = "ftp.basePath";
    String FTP_TIMEOUT_NAME = "ftp.timeout";
    String FTP_BUFFER_SIZE_NAME = "ftp.buffer.size";
    String FTP_MAX_TOTAL_NAME = "ftp.maxTotal";
    String FTP_MIN_IDLE_NAME = "ftp.minIdle";
    String FTP_MAX_IDLE_NAME = "ftp.maxIdle";

    /**
     * 上传类型定义
     */
    char FILE_UPLOAD_ONE = '1';
    char FILE_UPLOAD_TWO = '2';
    char FILE_UPLOAD_THREE = '3';

    /**
     * 文件入库的最大大小：100 kb
     */
    int FILE_MAX_SIZE = 100 << 10;

    BASE64Encoder BASE_64_ENCODER = new BASE64Encoder();
    BASE64Decoder BASE_64_DECODER = new BASE64Decoder();

    /**
     * 文件上传
     *
     * @param file       文件
     * @param uploadType 文件上传类型
     * @return 返回文件ID
     * @throws Exception 异常
     */
    RestfulRecord upload(MultipartFile file, Character uploadType) throws Exception;

    /**
     * 文件下载
     *
     * @param fileId   文件ID
     * @param response 下载
     * @throws Exception 异常
     */
    void download(String fileId, HttpServletResponse response) throws Exception;
}
